perm filename ALS10[F8,ALS] blob sn#300823 filedate 1977-08-11 generic text, type C, neo UTF8
COMMENT āŠ—   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	*      CHECKERS   REV  0.10
C00063 ENDMK
CāŠ—;
*      CHECKERS   REV  0.10
*     DATE 8/10/77  VERSION ALS
*
*Resident package addresses
JOYT   EQU     H'0C00'
SHCB   EQU     H'FDA'
WTLN   EQU     H'FDB'
DBNC   EQU     H'FDC'
INPF   EQU     H'FDD'  SET IT Tg 0 FOR FCS
LINE   EQU     H'FDE'
TXC    EQU     H'FE0'
CMRG   EQU     H'FE2'
UPI    EQU     H'FFA'
PUSH   EQU     H'4217'
POPS   EQU     H'422A'
UDAT   EQU     H'423E'
FCS    EQU     H'4316'
WAIT   EQU     H'4444'
WMS    EQU     H'4450'
TIR    EQU     H'45B9'
IJS    EQU     H'4670'
JOYI   EQU     H'4686'
*Misc. constants
TCMD   EQU     H'44'
BCMD   EQU     H'6D'
TCOL   EQU     H'80'   TEXT COLOR
ULIN   EQU     H'FF'
COM    EQU     H'8F7'
SLT    EQU     SKL
*
*RAM assignments
JOYK    EQU     H'0B23'   0 if JOY,  FF if  KEYBOARD
OBJ0    EQU     H'C30'
TREE    EQU     H'0E10'         Tree data (15 blocks of 16 bytes each)
BLCK    EQU     H'0E10'
WHT     EQU     H'0E20'
PLMD    EQU     H'0EC0'         Used for temp store of player's move info
PLMV    EQU     H'0ED0'         Overlay region used for player's moves
PLMF    EQU     H'0EE0'                 and move numbers
MOBS    EQU     H'0F00'         Mobility and DJ flags (14 bytes)
PLY0    EQU     H'0F0E'         Place for player's ply depth choice
COL0    EQU     H'0F0F'         Place for color choice (next after PLY0)
OBJ1    EQU     H'F10'  BOARD 2
*
*Scratch pad assignments
J      EQU     H'9'
HU     EQU     H'A'
HL     EQU     H'B'
PLOC    EQU     O'3'            LISU value for ACTIVE and PASSIVE
KLOC    EQU     O'4'            LISU value for KING's and special data
ELOC    EQU     O'5'            LISU value for EMPTY's area
ISA     EQU     O'30'           ISAR value for active area
ISP     EQU     O'34'           ISAR value for passive
ISK     EQU     O'40'           ISAR value for kings
ISE     EQU     O'51'           ISAR value for empty (with offset)
*Mimimum ply depths
PLYT    EQU     H'FE'           Ply depth for Robot Tom (stored as neg.)
PLYD    EQU     H'FD'           Ply depth for Robot Dick
PLYH    EQU     H'FC'           Ply depth for Robot Harry
*
       ORG     H'1000'
       DC      H'AA'
       DC      H'55'
       DC      H'00'   BACKGROUND COLOR
       DC      H'00'   BACKGROUND COLOR
       DC      H'00'   SPACES
       DC      H'00'   SPACES
       DC      H'3119' CH
       DC      H'0B31' EC
       DC      H'150B' KE
       DC      H'0921' RS
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
*
*      MAIN PROGRAM STARTS HERE
*
       LI      O'76'
       LR      IS,A
       LI      O'75'
       LR      S,A     SET STACK POINTER
*
*      SET INTERRUPT VECTOR
*
*      SET LINE INTERRUPT
*
        DI      DISABLE INTRPT
        LI      INHR:           Set INT vector in SMI
        OUTS    H'C'
        LI      INHR.
        OUTS    H'D'
        LIS     H'0'
        OUTS    H'E'             Disable SMI INT
*
       PI      QN1     WILL ASK QUES.#1
       PI      QN2
       PI      QN3
       PI      BRDI             Set up initial board
        PI      MEN             Put men on it
        DI                      Disable CPU interrupt
        DCI     CMRG            Reset INT bit in COM reg
        LR      Q,DC
        LM
        NI      H'F7'
        LR      DC,Q
        ST
        DCI     COM
        ST
       NOP
       NOP
       NOP
       NOP
OKPS    PI      JOYR            Read joystick
        BR      *               TEST LOOP FOR ABOVE
        PI      OKPI            Check if piece can move
        BZ      OKPS            Try again
OKMS    PI      JOYR            Read joystick a second time
        PI      OKMV            Check the move
        BR      *
        BZ      OKMS            Try again
*Code to move piece goes in here
*Then redo the board and men leaving cursor off
        LI      INHR:           Set INT vector in SMI
        OUTS    H'C'
        LI      INHR.
        OUTS    H'D'
        LI      ULIN            Set Y INT reg to FF
        DCI     H'8F0'
        ST
        LIS     H'08'           Set INT bit in COM reg
        DCI     CMRG
        LR      Q,DC
        OM
        LR      DC,Q
        ST
        DCI     COM
        ST
        LIS     1
        OUTS    H'E'            Enable SMI INT
        EI              Enable CPU INT
*Tree routine goes in here
        BR      *
*Subroutine to call MAP and thru it JOYI
JOYR    LR      K,P
        PI      PUSH
        LI      H'FF'           Wait for line FF
        DCI     WTLN
        ST
JOYL    PI      WAIT
        PI      UDAT
        PI      BORD            Regenerate board to wipe it clean
        PI      MEN             Put the men back on
        PI      MAP             Map joystick into board position and set cursor
        CLR                     Read push button
        OUTS    1
        INS     1
        NI      1
        BZ      JOYL            Loop until button is pushed
        PI      POPS
        PK
*The following may be useful but is not now used
       LI      H'7F'
       LR      0,A
LOP0   LI     H'7F'
       LR      1,A
LOP1   NOP
       DS      1
       BP      LOP1
       DS      0
       BP      LOP0
       NOP
       NOP
       NOP
       NOP
       BR       *
*********************************************************
*
*      FIRST QUES. WILL BE FOR
*      SKILL LEVLE SELECTION.
*      DEF. IS LOWEST LEVEL 'TOM'
*      PLY LEVEL STRORED IN LOC H'F0E'
*
*********************************************************
QN1    LR      K,P     SAVE RETURN 
       PI      PUSH    PUSH IT ON STACK
       PI      TINT    TEXT INIT
       LISU    O'2'
       LISL    O'4'
       LI      H'40'   H40=D64
       LR      S,A     SET REG24
       DCI     LINE
       LI      H'20'   LINE # 2 POS. 0
       ST
       DCI     SKL     SKILL LEVEL TABLE
       PI      WMS     WRITE MASSAGE
*
*      TEXT IS DISPLAYED ,LOOK FOR REPLY NOW
*
       PI      RKB     READ KEYBOARD
       CI      H'1F'   IS IT DICK?
       BNZ     QN12    No
       LI      PLYD
       BR      QN14
QN12   CI      H'19'   IS IT HARRY?
       BNZ     QN13    No, it must be Tom
       LI      PLYH
       BR      QN14
QN13   LI      PLYT
QN14   DCI     PLY0
       ST
       PI      POPS
       PK
***************************************?*****************************
*
*      QUESTION 2 ROUTINE    QN2
*
*********************************************************************
*
*
*      INPUT MODE KBD/JSTK/
*      PLY0,BIT7=0 JOYSTICK
*            BIT7=1 KEYBOARD
*
*
QN2    LR      K,P     SAVE RETURN ADDR
       PI      PUSH
       PI      TINT    INIT.TEXT
       LISU    O'2'
       LISL    O'4'    SET ISAR
       LI      H'30'   #OF CHARS.
       LR      S,A     PUT IT IN '24'
       DCI     LINE
       LI      H'30'   LINE 3 POS.0
       ST
       DCI     INJK    TEXT TABLE ADDR.
       PI      WMS
       PI      RKB     READ KEYBOARD
       CI      H'15'   IS IT K?
       DCI     JOYK
       LIS     H'F'    F if keyboard
       BZ      INJ     It is K
       PI      IJS     Init joystick
       DCI     JOYK
       CLR             0 if joystick
INJ    ST
       PI      POPS
       PK              RETURN
*
*      END OF QUEST 2
*
********************************************************************
*
*      QUESTION 3 ROUTINE   QN3
*      QUEST # 3
*      YOU MOVE FIRST?
*      Y/N (H)=E10 Y, (H) =E20 N
*
********************************************************************
*
QN3    LR      K,P     SAVE RET. ADDR
       PI      PUSH
       PI      TINT    TXT INIT
       LISU    O'2'
       LISL    O'4'
       LI      H'1A'   H1A=D   CHARS.
       LR      S,A     PUT IT IN 24
       DCI     LINE
       LI      H'30'
       ST
       DCI     YMF     
       PI      WMS
       PI      RKB     GET ANSWER FROM KBD
       CI      H'2B'   IS IT 'N'?
       BZ      QN31    ITS N
       DCI     BLCK    DEF. BLACK
QN32   LR      H,DC    PUT IT IN H
       PI      POPS
       PK
QN31   DCI     WHT
* A DUMMY LINE TO FIX AN ASSEMBLY ERROR
       BR      QN32
*
*      END OF QUEST 3
*
***************************************************************
*
*      TINT TEXT INITIALIZATION
*
************************************************************
TINT   LR      K,P     SAVE RETURN
       PI      PUSH
       PI      RST     RESET UM1 REGS.
TNT1   DCI     H'8FB'
       LIS     H'8'
       XM      
       BNZ     TNT1
       DCI     CMRG    PROG COPY OF COM REG.
       LI      TCMD     DISPLAY COMMAND
       ST
       DCI     H'C18'
       CLR
       ST
       DCI     WTLN
       LI      ULIN    WAIT LINE
       ST
       DCI     TXC     TEXTCOLOR
       LI      TCOL
       ST
       PI      TIR     CALL TEXT INIT
       PI      POPS
       PK
*
**********************************************************
*
*      RST RESETS UM1 REGS.
*
**********************************************************
RST    LR      K,P     CLR R/W REGS.
       LI      H'80'
       LR      0,A
       LI      H'FF'
       DCI     H'800'
RST1   ST
       DS      0
       BNZ     RST1
       DCI     H'8F0'  CLR WRITE ONLY REGS
       LIS     H'8'
       LR      0,A
       CLR
RST2   ST
       DS      0
       BNZ     RST2
       PK
*
**************************************************************
*
*      KEYBORD READ
*
**************************************************************
RKB    LR      K,P
       PI      PUSH
       CLR
       DCI     INPF    CLEAR FLAG
       ST
       DCI     DBNC
       ST
       DCI     SHCB    CLER    SHIFT CONTROL
       ST
       DCI     CMRG
       LI      TCMD
       ST
       LISU    O'2'
       LISL    O'4'
       LI      H'C0'   WAIT TIME FOR FCS
       LR      S,A     PUT IT IN '24'
RKB1   PI      FCS     GET CHAR.
       BZ      RKB1    WAIT FOR ANY KEY
       LR      A,8     RETURN CHAR IN AC
       PI      POPS
       PK
*
************************************************************************
*
*      BOARD IMAGE ROUTINE
*
******************************************
*
BRDI   LR      K,P     SAVE RETURN
       NOP
       NOP
       NOP
       PI      PUSH
       PI      RST     RESET UM1 REG
       PI      BORD    GENERATE BOARD
       PI      SURP    SET UM1 REGS AND POINTERS
*
*Put in initial pieces both in SC and in blocks 0 or 1
        LISU    PLOC
        LISL    H'0'
        LI      H'FF'           Full double row of pieces
        LR      I,A             First byte of ACTIVE
        LI      H'F0'           1 row only
        LR      I,A             Second byte of active
        CLR 
        LR      I,A             Part of board with no active pieces
        LR      I,A             Part of board with no active pieces
        LR      I,A             Part of board with no passive pieces
        LR      I,A             Part of board with no passive pieces
        LI      H'F'            1 row only (in second half of byte)
        LR      I,A             byte of PASSIVE
        LI      H'FF'           Full double row of pieces
        LR      I,A             Last byte with Passive pieces
        LISU    KLOC
        LISL    0
        CLR
        LR      I,A             4 king bytes next (all empty)
        LR      I,A
        LR      I,A
        LR      I,A
        LI      H'F0'           The 4 bits for pieces that can move RF
        LR      I,A             The MOVE byte
        LIS     H'4'            BYTE # 1 RF normal move with no piece debit
        LR      I,A             
        LI      H'80'           Set score at -128 (lose, unless move is found)
        LR      I,A
        CLR                     With position advantage of 0
        LR      I,A
*       LR      DC,H            This was set earlier
*       PI      SCRD            Store pieces in correct RAM pos.
*       LR      DC,H
        CLR                     Should put black at bottom
        COM                     Should put red at bottom
        DCI     COL0
        ST
        PI      MEN
* A DUMMY LINE TO FIX AN ASSEMBLY ERROR
        PI      POPS
        PK
* Code to read the internal representation of the board and to put the
* required pieces into the board image.
*
MEN     LISU    O'3'            Start with pieces
        LIS     H'1'            1 for red pieces (shown first always)
        LR      4,A             To specify piece color (1 red, 0 black, -1 king)
        XDC
        DCI     COL0
        LM
        XDC
        LR      7,A
        LR      A,11
        SR      4
        AI      H'FF'
        LR      A,7
        BZ      *+2
        COM
        LR      7,A
        NS      7               Set status
        LISL    O'7'            Decrement if black is active and shift right
        BZ      MEN1            Black is active (Appears at bottom of screen)
        LISL    O'0'            Red is active, increment and shift left
MEN1    LIS     H'3'
        LR      1,A             To count bytes
MEN2    LIS     H'7'
        LR      2,A             To count bits
        DCI     TAB1            STARTING ADDRESS FOR BYTE LOCATION
        LR      A,1             This byte number
        SL      1               Locations occupy 2 bytes each
        ADC
        LM                      Get the location
        LR      QU,A            and save it in Q
        LM
        LR      QL,A
        LR      A,7
        NS      7
        BZ      MEN5            Black is active
        LR      A,I             Increment if red is active
        BR      MEN4
MEN3    LR      A,3
        SL      1               and shift left
MEN4    LR      3,A
        NI      H'80'           (done this way for symetry, BC would work)
        BZ      MEN9
        BR      MEN8
MEN5    LR      A,D             Decrement if black is active
        BR      MEN7
MEN6    LR      A,3
        SR      1               and shift right
MEN7    LR      3,A
        NI      H'1'
        BZ      MEN9
MEN8    DCI     TAB2            Relative-locations-of-squares table
        LR      A,2             This square
        ADC
        LM                      Get square displacement
        LR      DC,Q            Recall the location for the input byte
        ADC                     This is the square position
        LR      A,4             Identify type of piece
        NS      4
        BM      PUTK            To put down a king
        LIS     H'4'            Prepare for a piece
        LR      5,A             To count lines
        LI      H'20'           Skip the first 4 lines (4*8)
        ADC
        XDC
        DCI     BLKP            Anticipate a black piece
        BZ      PUTL            A black piece (status bit still ok)
        DCI     REDP            No, it's a red piece
        BR      PUTL
PUTK    LIS     H'2'            Only 3 lines for a crown
        LR      5,A
        LIS     H'8'            To skip 1 line
        ADC
        XDC
        DCI     KING
PUTL    LM                      Put loop
        XDC
        ST
        LIS     H'7'            To next line on screen (less increment)
        ADC
        XDC
        DS      5
        BP      PUTL            Loop
MEN9    DS      2
        BM      ME10
        LR      A,7
        NS      7
        BZ      MEN6            Black active case
        BR      MEN3            Red active case
ME10    DS      1
        BP      MEN2            For the next input byte
        LR      A,4
        NS      4
        BM      BDEX            Exit from board routine
        DS      4
        BP      MEN1            Go round again for black pieces
        LISU    H'4'            Get set for kings
        LR      A,7
        NS      7
        LISL    H'3'            Decrementing case
        BZ      MEN1
        LISL    H'0'            Incrementing case
        BR      MEN1
BDEX    POP
*
***********************************************************************
*
*      BORD GENERATES BOARD IMAGE
*
************************************************************************
*
BORD   LR      K,P
       PI      PUSH
       LI      H'FF'
       LR      3,A     REG3=FF
       DCI     OBJ0    BRD1 START ADDRESS
       LIS     H'2'    FLAG FOR BORD
       LR      4,A     SET REG 4 = 2
       LIS     H'6'
BRD4   LR      0,A     REG0 = 6 ROWS
BRD3   LIS     H'A'
       LR      1,A     REG 1 = 10 LINE/ROW
BRD2   LIS     H'4'
       LR      2,A     REG2=SQ PAIRS/ROW
BRD1   LR      A,3
       ST              STORE IN BRD
       COM
       ST              NEXT IS COMPL. OF FIRST
       DS      2
       BNZ     BRD1    MORE FOR THIS ROW
       DS      1       NO, ALL LINE DONE
       BNZ     BRD2
       LR      A,3     DONE A TIMES YET
       COM
       LR      3,A
       DS      0       DEC ROW COUNT
       BNZ     BRD3    ALL ROWS DONE?
       DS      4
       BZ      BRD5    BOTH OBJECTS DONE?
       DCI     OBJ1    NO,GET BORD2 ADDRS.
       LIS     H'2'
       BR      BRD4    REG0=2
BRD5   PI      POPS
       PK
***********************************************************************
*
*      SURP SETS UM1 REGS & PTRS
*
***********************************************************************
SURP   LR      K,P
       PI      PUSH
       DCI     H'800'  UM1     REG START
       XDC             TUCK IT AWAY
       DCI     INIT    INIT TABLE POINTER
       LIS     H'6'
       LR      0,A
SRP1   LM              READ INIT TABLE
       XDC
       ST              PUT  IN UM1
       XDC             PT. BACK TO INIT
       LM              READ TABLE
       XDC
       ST
       DS      0       REG 0 = COUNTER 6
       BZ      SRP2
       LIS     H'E'
       ADC
       XDC
       BR      SRP1    CONTINUE
SRP2   LI      H'1E'   DO LAST TWO ENTRIES
       ADC     
       XDC
       LM              GET IT FROM INIT TAB
       XDC
       ST              PUT IT UM1
       XDC
       LM              GET IT FROM
       XDC
       ST
*
*      SET UPI PTRS
*
       DCI     UDIT
       LR      Q,DC
       DCI     UPI
       LIS     H'2'
       ST
       ST
       LR      A,QU
       ST
       LR      A,QL
       ST              ODD
       LR      A,QU
       ST
       LR      A,QL
       ST
       PI      POPS
       PK
*
* Subroutine to move data from RAM to S O'30' thru O'47' with the data for
* S O'30' thru O'43' coming from the current block.  Data for O '44' thru
* O'47' is from the previous block, with some items deleted.
*
RASC    LR      K,P             Save return address
        LISU    PLOC            SC buffer with Active and Passive
        LISL    0
        LIS     H'8'
        LR      0,A
        PI      RASL
        LISU    KLOC            SC buffer with Kings 
        LISL    0
        LIS     H'4'
        LR      0,A
        PI      RASL
        LI      H'F1'           Rest of data from earlier block
        ADC
        CLR                     Zero the MOVE byte
        LR      I,A
        LM
        NI      H'E0'           Save Piece debit only
        LR      I,A
        LM
        LR      I,A             Keep both SCORE bytes
        LM
        LR      I,A
        PK
*
RASL    LM
        LR      I,A
        DS      0
        BNZ     RASL
        POP
*
*Subroutine to move 16 bytes from SC O'30' thru O'47' to RAM direct.
SCRD    LR      K,P
        LISU    PLOC
        LISL    0
        LIS     H'8'
        LR      0,A
        PI      SCRL
        LISU    KLOC
        LISL    0
        LIS     H'8'
        LR      0,A
        PI      SCRL
        PK
*
*Subroutine to move 16 bytes from SC O'30' thru O'47' to RAM, reversing
*ACTIVE and PASSIVE and deleting some items
SCRA    LR      K,P
        LISU    PLOC
        LISL    4
        LIS     H'4'
        LR      0,A
        PI      SCRL
        LISL    0
        LIS     H'4'
        LR      0,A
        PI      SCRL
        LISU    KLOC
        LISL    0
        LIS     H'4'
        LR      0,A
        PI      SCRL
        LR      A,I             To index only
        CLR                     Zero MOVE byte
        ST
        LR      A,I
        NI      H'E0'           Save piece debit only
        LR      A,I
        ST                      Save both SCORE bytes
        LR      A,I
        ST
        PK
*
SCRL    LR      A,I
        ST
        DS      0
        BNZ     SCRL
        POP
*
*To compute 4 bytes which show the empty squares on the board and store
*them in O'51' thru O'54' with O'50' and O'55' set to zero as guards.
*Note especially that the EMPTY locations are displaced relative to ACTIVE.
EMPTY   LISU    ELOC
        LISL    0
        CLR
        LR      S,A             Make sure guard byte is empty
        LISU    PLOC            Start with ACTIVE
        LIS     H'4'
        LR      0,A
        BR      EMP3
EMP2    LR      A,IS
        AI      H'30'           Actually subtracting 16
        LR      IS,A
EMP3    LR      A,S
        LR      1,A
        LR      A,IS
        AI      4
        LR      IS,A
        LR      A,S
        AS      1
        LR      1,A
        LR      A,IS
        AI      H'D'            Add 13 to get to the correct EMPTY location
        LR      IS,A
        LR      A,1
        COM                     Reverse 1's and 0's
        LR      S,A
        DS      0
        BNZ     EMP2
        CLR
        LR      S,A             Upper guard byte
        POP
*
*Subroutine to count bits in 0 and return count in A
*Uses registers 0 and 1
CAQ     CLR
        LR      1,A
        LR      A,0
        BR      CAQ3
CAQ2    DS      1
        AI      H'FF'
        NS      0
        LR      0,A
CAQ3    BNZ     CAQ2
        LR      A,1
        COM
        INC             Make it into a true positive number
        POP
*
*Subroutine to multiply 2 positive binary numbers (the smaller in SC 1 and
*the larger in SC 2) by Russian multiplication.  SC 0 is used to accumulate
*the product.  This code may be used at only one place and can probably be
*written in line at that place with some saving of space.
*
MPYR    CLR
        LR      0,A             To accumulate the product
        LR      A,1
MPY1    NI      H'1'            Is the rightmost bit a 1?
        BZ      MPY2            No
        LR      A,2
        AS      0
        LR      0,A
MPY2    LR      A,2
        SL      1
        LR      2,A
        LR      A,1
        SR      1
        LR      1,A
        BNZ     MPY1            Product is not complete
        POP
*MAP  Code to convert joystick reading into cursor position on board.
*Cursor's position on the board image is limited to the playing squares.
*When the joystick is moved the cursor jumps from playing square to
*playing square, always landing on that square that is nearest to the
*indicated joystick position.
*
*Requires X and Y readings from joystick in 1 and 2 respectively.
*Returns byte in 3 (with one bit on for square) and byte number in 4 and
*puts cursor into board image.  Note that the board and its pieces image
*must be regenerated to remove the trace of the cursor' former positions.
*Uses reg 0 in addition to 1, 2, 3, and 4.
MAP     LR      K,P
        PI      PUSH
        LIS     H'01'   GET X
        LR      HU,A
        PI      JOYI
        PI      MAPA
        LR      1,A
        CLR
        LR      HU,A
        PI      JOYI
        PI      MAPA
        LR      2,A
        AS      1
        LR      3,A             Unnormalized sum in 3
        LIS     H'8'
        LR      0,A
        LR      A,3
MAP2    DS      0
        AI      H'F9'           Sub 7
        BP      MAP2
        LR      A,0
        LR      3,A             Sum into 3, range 0 thru 6
        LR      A,1
        COM
        AI      D'25'
        AS      2
        LR      4,A             Unnormalized difference in 4
        LIS     H'9'            Need 8 catagories for the difference
        LR      0,A
        LR      A,4
MAP3    DS      0
        AI      H'FD'           Sub 3
        BP      MAP3
        LR      A,0
        LR      4,A             Difference into 4, range 0 thru 7
        COM
        INC
        AS      3
        INC
        LR      1,A             Normalized X value
        LR      A,4
        AS      3
        INC
        SR      1
        LR      2,A             Normalized Y value
        SR      1
        LR      4,A             The byte number left in 4
        LR      A,1
        SR      1
        INC
        LR      3,A
        LIS     H'8'
        BR      MAP5
MAP4    SR      1
MAP5    DS      3
        BNZ     MAP4
        LR      A,1
        NI      H'1'
        BNZ     MAP6
        LR      A,3
        SR      4
        LR      3,A
MAP6    NOP                     Byte with bit on left in 3
        LR      A,1
        SR      1
        LR      1,A
        LR      A,2
        NI      H'1'
        BZ      MAP7
        LR      A,1
        AI      H'4'
        LR      1,A             This is now the offset in the byte
MAP7    NOP
        DCI     TAB1
        LR      A,4
        SL      1
        ADC
        LM
        LR      QU,A
        LM
        LR      QL,A
        LIS     H'4'
        LR      5,A
        DCI     TAB2
        LR      A,1
        ADC
        LM
        LR      DC,Q
        ADC
        XDC
        DCI     POIN
PUTP    LM
        XDC
        OM
        LR      0,A
        LI      H'FF'
        ADC
        LR      A,0
        ST
        LIS     H'7'
        ADC
        XDC
        DS      5
        BP      PUTP
        PI      POPS
        PK
*
*Subroutine to reduce range and invert if necessary
MAPA    SR      1
        SR      1
        SR      1
        LR      0,A
        LR      A,7             Check color
        NS      7
        BNZ     MAPB            Do we need to invert?
        LR      A,0
        COM
        AI      D'25'
MAPB    POP
*
* Code to verify that indicated piece can, in fact, move.
* The byte showing the piece is in 3 and the byte # is in 4 without
* the jump bit and the direction as yet.
OKPI    DCI     PLMV            Possible moves listing
        LM                      Number of entries here
        ADC
        CLR
        ST                      Set zero to stop search
        DCI     PLMV
        LM                      Skip the number of entries
OKP1    LM                      Get first move byte
        NI      H'FF'
        BZ      OKNO            No more entries
        NS      3
        BNZ     OKP2            This might be the one
        CM                      A cheap way to index
        BR      OKP1            Try again
OKP2    LM                      Next entry is the byte info
        NI      H'0C'           Remove the J bit and the direction
        XS      4               Does it match?
        BNZ     OKP1            Try again
        LR      Q,DC
        XDC                     Save data position
        DCI     PLMD            Save data as to starting square
        LR      A,QU            So we can use Q freely if need be
        ST
        LR      A,QL
        ST
        LR      A,1
        ST                      Save the normalized X position
        LR      A,2
        ST                      and the normalized Y position
        LR      A,3
        ST                      Save player's starting byte
        LR      A,4
        ST                      and the Byte number
*We may want to signal the success by some audible signal 
        POP
*
*We will want th indicate failure, perhaps by a growl before going back
*to letting the player try to find a piece that can move
OKNO    CLR                    Clear 3 to show that piece cannot move
        LR      3,A
        POP
* We have found that the piece can move but we do not yet know the
*intended direction and there may be more than 1 direction possible.
**** NOW FOLLOW THE JOYSTICK AND WAIT FOR ANOTHER HIT.
OKMV    DCI     PLMD
        LM
        LR      QU,A
        LM
        LR      QL,A
        LM                      Get the old X value
        COM
        INC
        AS      1               This gives us the change in X
        LR      5,A
        LM                      Get the old Y value
        COM
        INC
        AS      2
        LR      6,A
        BM      OKM4
        CI      H'01'
        BZ      OKM2            It was a normal forward move
        CI      H'02'
        BNZ     NONO            Not a legal move
        LR      A,5
        CI      H'02'
        BNZ     OKM1
        LI      H'10'           A RFJ move
        BR      OKN             Still must make sure
OKM1    CI      H'FE'
        BNZ     NONO
        LI      H'11'           A LFJ move
        BR      OKN
OKM2    LR      A,5
        CI      H'01'
        BNZ     OKM3
        CLR                     A RFN move
        BR      OKN
OKM3    CI      H'FF'
        BNZ     NONO
        LIS     H'01'           A LFN move
        BR      OKN
OKM4    CI      H'FF'
        BZ      OKM6
        CI      H'FE'
        BNZ     NONO
        LR      A,5
        CI      H'02'
        BNZ     OKM5
        LI      H'12'           A RBJ jump
        BR      OKN
OKM5    CI      H'FE'
        BNZ     NONO
        LI      H'13'           A LBJ jump
        BR      OKN
OKM6    LR      A,5
        CI      H'01'
        BNZ     OKM7
        LI      H'01'           A RBN move
        BR      OKN
OKM7    CI      H'FF'
        BNZ     NONO
        LI      H'11'           A LBN move
OKN     AS      4               Add the byte number
        LR      4,A             and save the complete byte info 
        LI      H'FF'           Back up
        ADC
OKN2    LR      A,4
        CM                      Is it the same?
        BZ      OKOK            Found!
OKN3    LM                      Go to the next entry
        NI      H'FF'
        BZ      NONO
        NS      3
        BNZ     OKN2            A bit matches here
        CM                      A cheap way to index
        BR      OKN3            
NONO    NOP
*We will now have to signal that he has picked a piece that can move but
*it can not move to the square chosen and that the player is to try again
OKOK    DCI     TREE            Now get back to the Tree routine
        LR      H,DC
        LIS     H'C'
        ADC
        LR      A,3
        ST
        LM
        NI      H'D0'
        AS      4
        LR      4,A
        LI      H'FF'
        ADC
        LR      A,4
        ST
        LR      DC,H
*Now we signal success and proceed to make the player's move and go on to
*find the machine's move
*
       ORG     H'17C0'
*   INHR  INTERRUPT HANDLER
*
*   WILL STORE ENVIRONMENT BEFORE CALLING UDAT
*   AND RESTORE BEFORE GOING BACK'
*
INHR   LR      6,A     SAVE ACC
       LR      A,IS
       LISU    O'6'
       LISL    O'0'
       LR      I,A     SAVE A IN REG24
       LR      A,QU
       LR      I,A     SAVE QU IN REG25
       LR      A,QL
       LR      I,A     SAVE QL IN REG26
       LR      A,J
       LR      I,A     SAV IN REG27
       XDC
       LR      Q,DC    GET DC
       DCI     H'0FB0' GET FREE RAM ADDR.
       LR      A,QU    SAVE ORIGINAL DC1
       ST
       LR      A,QL
       ST
       XDC
       LR      Q,DC
       XDC
       LR      A,KU
       ST
       LR      A,KL
       ST              SAVE KL
       LR      A,10    UPPER H
       ST              SAVE IT
       LR      A,11
       ST              SAVE H
       LR      J,W
       LR      A,J
       ST              SAVE W
       LR      K,P
       LR      A,KU
       ST              SAVE PCU
       LR      A,KL
       ST              SAVE PCL
       LR      A,QU    SAVE DC0 ORIGINAL
       ST
       LR      A,QL
       ST
       PI      UDAT    UPTE DISPLAY
*
*   RESTORE ALL REGISTERS
*
       DCI     H'0FB0'
       LM
       LR      QU,A    GET DC1
       LM
       LR      QL,A
       XDC
       LR      DC,Q    RESTORE DC1
       XDC
       LIS     H'2'
       ADC             BYPASS 'K' SAVED AREA
       LM              GET HU
       LR      HU,A    RESTORE HU
       LM
       LR      HL,A    RESTORE HL
       LM              GET W
       LR      J,A
       LR      W,J     RESTORE IT
       LM              GET PC1 HO
       LR      KU,A
       LM
       LR      KL,A
       LR      P,K     RESTORE PC1
       LM
       LR      QU,A
       LM
       LR      QL,A
       DCI     H'FB2'        PT TO K
       LM              GET KU
       LR      KU,A
       LM
       LR      KL,A    RESTORE K
       LR      DC,Q    RESTORE DC0
*
*   NOW RESTORE J,Q,A FROM SCRATCH PAD
*
       LISU    O'6'
       LISL    O'3'
       LR      A,D     GET J
       LR      J,A
       LR      A,D   GET QL
       LR      QL,A
       LR      A,D
       LR      QU,A    RESTORE QU
       LR      A,D     GET ISAR
       LR      IS,A    RESTORE ISAR
       LR      A,6     RESTORE A
       EI              INT. ENABLE
       POP     
*   DISPALY YOU MOVE FIRST?
*             Y OR N
*
*
YMF    DC      H'0513' Y0
       DC      H'0300' U-
       DC      H'2913' MO
       DC      H'2F0B' VE
       DC      H'00'   -
       DC      H'1D'   F
       DC      H'0109' IR
       DC      H'2107' ST
       DC      H'00'   -
       DC      H'35'   ?
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'0500' Y-
       DC      H'1309' OR
       DC      H'00'   -
       DC      H'2B'   N
*   INIT  DATA
INIT   DC      H'30'   OBJ0 L.O.RP
       DC      H'10'   OBJ1 L.O. RP
       DC      H'8C'   OBJ0 H.O.RP+COLOR
       DC      H'8F'   OBJ1    H.O.RP
       DC      H'48'   OBJ0 DELTA X ---
       DC      H'48'   OBJ1 DELTA X---
TY0   DC      H'3C'   OBJ0 DELTA Y ----
       DC      H'14'  OBJ1 DELTA Y ---
       DC      H'0D'   OBJ0-X-CO
       DC      H'0D'   OBJ1 X-CO
       DC      H'47'   OBJ0 Y-VALUE L.O.A
       DC      H'BE'   OBJ1 Y-VALUE L.O.A
       DC      H'00'   OBJ0 Y-VALUE H.0 &X-ORDER
       DC      H'01'   OBJ1- Y-VAL H.O.$X-ORDER
*A DUMMY LINE TO FIX AN ASSEMBLY ERROR
UDIT   DC      H'30'
       DC      H'10'
       DC      H'8C'
       DC      H'8F'
        DC      H'3C'
        DC      H'14'
TAB1   DC      H'0F10' BYTE 3
       DC      H'0D70' BYTE 2
       DC      H'0CD0' BYTE 1
       DC      H'0C30' BYTE 0
TAB2   DC      D'86'   RELATIVE SQUARE POSITION TABLE
       DC      D'84'
       DC      D'82'
       DC      D'80'
       DC      D'07'
       DC      D'05'
       DC      D'03'
       DC      D'01'
KING   DC      B'01011010'     KING'S CROWN
       DC      B'00111100'
       DC      B'00011000'
REDP   DC      B'00111100'     RED PIECE
       DC      B'01111110'
       DC      B'01111110'
       DC      B'01111110'
       DC      B'00111100'
BLKP   DC      B'00111100'     BLACK PIECE
       DC      B'01000010'
       DC      B'01000010'
       DC      B'01000010'
       DC      B'00111100'
POIN   DC      B'00001100'
       DC      B'00000110'
       DC      B'00000011'
       DC      B'00000001'
*******************************************************************
*
*   SKILL LEVEL TEXT TABLE
*
********************************************************************
SKL    DC      H'3119' CH
       DC      H'1313' OO
       DC      H'210B' SE
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'150B' KE
       DC      H'0500' Y-
       DC      H'00'   -
       DC      H'00'   -
       DC      H'0713' TO
       DC      H'2900' M-
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'07'   T
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
DICK   DC      H'1F01' DI
       DC      H'3115' CK
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'1F'   D
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
HARY   DC      H'1911' HA
       DC      H'0909' RR
       DC      H'0500' Y-
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'19'   H
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
*
*   64 BYTES TABLE FOR 
*   CHOOSE SKILL LEVEL
*    INPUT MODE J/K
*
INJK   DC      H'012B' IN
       DC      H'2503' PU
       DC      H'0700' T-
       DC      H'00'   -
       DC      H'00'   -
       DC      H'2913' MO
       DC      H'1F0B' DE
       DC      H'00'   -
       DC      H'35'   ?
       DC      H'00'   -
       DC      H'00'   -
KBRD   DC      H'150B' KE
       DC      H'052D' YB
       DC      H'1311' OA
       DC      H'091F' RD
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'15'   K
       DC      H'00'   -
       DC      H'00'   -
       DC      H'1713' JO
       DC      H'0521' YS
       DC      H'0701' TI
       DC      H'3115' CK
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'00'   -
       DC      H'17'   J
       DC      H'00'   -
       DC      H'00'   -
*
*   END OF zINPUT MGDE TABLE 
*   48 BYTES
*
       END